<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!-- Begin: Content -->
      <section id="content" class="table-layout">
<!--start 内容--------------------------->	
 <form  method="post" id="dataHuiShouForm" name="dataHuiShouForm">
		 <!-- create new order panel -->
          <div class="panel mb25 mt5">
            <div class="panel-heading">
              <span class="panel-title hidden-xs"></span>
              <ul class="nav panel-tabs-border panel-tabs">
                <li class="active">
                  <a href="#tab1_1" data-toggle="tab">无条码包回收登记</a>
                </li>
              </ul>
            </div>
            <div class="panel-body p20 pb10">
              <div class="tab-content pn br-n admin-form">
                <div id="tab1_1" class="tab-pane active">
				  <div class="section row">
              		<div class="col-md-6">   
                    	临床科室              	
                      <label class="field select">
	                        <select class="empty" id="packageDepartid" name="packageDepartid" onchange="showPack()">
	                        	<!-- <option value="">所有科室</option> -->
	                          	 <c:if test="${departs !=null }">
		                        	<c:forEach items="${departs }" var="dep">
		                       			<option  <c:if test="${operpackage.packageDepartid==dep.departmentId}">selected='selected'</c:if>    value="${dep.departmentId}">${dep.departmentName}</option>
		                       		</c:forEach>
		                        </c:if>
	                        </select>
	                        <i class="arrow double"></i>
	                      </label> 
                    </div>
                    
                    <div class="col-md-6">   
                     	 包筛选(简码)
                     	<label for="packageName" class="field prepend-icon">
	                        <input name="packageName" id="packageName" class="gui-input" placeholder="手术包简码" type="text" value="" onkeyup="showPack()">
	                        <label for="packageName" class="field-icon">
	                          <i class="fa fa-tag"></i>
	                        </label>
	                    </label> 
                    </div>
                    <div class="col-md-6"> 
	                    <table class="table table-bordered admin-form theme-warning tc-checkbox-1 fs13" id="tbpck">
		                  <thead>
		                    <tr class="bg-light">
		                      <th class="text-left">包名称</th>
		                      <th class="text-left">包数量</th>
		                    </tr>
		                  </thead>
		                  <tbody>
		                  	
		                  </tbody>
	                	</table>
                	</div>
                  </div>
                      <hr class="short alt">
                  </div>
                  <div class="section row mbn">
                    <div class="col-md-12">
                      <p class="text-right">
                      	<button class="btn btn-primary" type="button" id="save">确定</button>
                        <button class="btn btn-warning" type="button" id="back">取消</button>
                      </p>
                    </div>
                  </div>
              </div>
            </div>
          </div>
</form>		 
<!-- end 内容----------------------------->		
      </section>
      <!-- End: Content --> 
  <!-- End: Main -->
<script src="${ctx}/js/utility.js"></script>
<script src="${ctx}/js/main.js"></script> 
<script src="${ctx}/js/demo.js"></script>
  
  <script type="text/javascript">
	 function showPack(){
		var url = "${ctx}/zsHuiShou/findHuishouPackageByDepart.do?packageDepartid="+$("#packageDepartid").val()+"&packageNo="+$("#packageName").val();
		console.log(url);
		$.ajax({
	          type: "POST",
	          url:url,
	          data:$('#dataHuiShouForm').serialize(),// 你的formid
	          error: function(request) {
	         	 layer.alert("网络故障，请稍后再试!");
	          },
	          success: function(data) {
	         	 if(data.status=="true"){
	         		$("#tbpck tbody").empty();
	         		 var dt = data.packages;
	         		 var str = '';
	         		 for(var i = 0;i<dt.length;i++){
	         			 str +='<tr><td class="text-left">'+dt[i].packageName+'</td><td><input type="hidden" name="pid" value="'+dt[i].packageId+'"/><input type="text" name="packnums" class="gui-input"/><input type="hidden" name="pname" value="'+dt[i].packageName+'"/></td></tr>'
	         		 }
	         		 $("#tbpck tbody").append(str)
	         	 }
	          }
	      });		
	 }
 function do_save(){
	 var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	 var rtnJson= new Array();
	 $("input[name='packnums']").each(function(index,element){
		 var id = $(this).prev().val();
		 var name = $(this).next().val();
		 var val = $(this).val();
		 var depId =$("#packageDepartid").val();
		 var depVal= $("#packageDepartid").find("option:selected").text(); 
		 if(val != '') {
			 var obj = new Object();
			 obj.packId=id ;
			 obj.packName=name;
			 obj.packNum =val;
			 obj.depId = depId;
			 obj.depVal = depVal;
			 rtnJson.push(obj);
			 //console.log(rtnJson);	 
		 }
	 })
 	 parent.callbackData(rtnJson);
 	 parent.layer.close(index); //再执行关闭   
 }
  jQuery(document).ready(function() {
	    "use strict";   
	    Core.init();  
	    Demo.init();
	    showPack();
	    $("#back").click(function(){
	    	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	    	parent.layer.close(index); //再执行关闭 
	    });
		 
		$("#save").click(function(){
			do_save();
		});
  });
  
 
  </script>
  </body>
</html>
